import Axios, { AxiosRequestConfig } from "axios";
import { useUserStore } from '@/store'

const host = window.location.host

const client = Axios.create({
  baseURL: `http://${host}`,
  timeout: 5000
})

const userStore = useUserStore()

export async function request(url: string, config?: AxiosRequestConfig) {
  const response = await client.request({
    url,
    headers: {
      token: userStore.token
    },
    ...config
  })
  const result = response.data
  // 你的业务判断逻辑
  return result
}